// index.js
const util = require("../../utils/utils.js");
const api = require("../../config/api.js");
Page({
  data: {
    newGoods: [], //新品首发
    hotGoods: [], //人气推荐
    topics: [], //专题精选
    brands: [], //品牌制造商
    groupons: [], //团购专区
    floorGoods: [], // 居家层级数据
    banner: [], // 轮播图
    channel: [], // 九宫格
    coupon: [], // 优惠券
    goodsCount: 0 // 商品搜索框数量
  },
  gotoDetail: function (e) {
    //console.log(e.currentTarget.id);
    wx.navigateTo({
      url: '/pages/goodsdetail/goodsdetail?id=' + e.currentTarget.id,
    })
  },
  getIndexData: async function () {
    let res1 = await util.request(api.IndexUrl);
    //console.log(res1);
    if (res1.errno == 0) {
      this.setData({
        newGoods: res1.data.newGoodsList,
        hotGoods: res1.data.hotGoodsList,
        topics: res1.data.topicList,
        brands: res1.data.brandList,
        groupons: res1.data.grouponList,
        floorGoods: res1.data.floorGoodsList,
        banner: res1.data.banner,
        channel: res1.data.channel,
        coupon: res1.data.couponList,
      })
    }
    let res2 = await util.request(api.GoodsCountUrl);
    if (res2.errno == 0) {
      this.setData({
        goodsCount: res2.data.goodsCount
      })
    }
  },
  onLoad: function (options) {
    this.getIndexData()
  }
})
